import React, { createRef, useRef } from "react";

export default function GetDom() {
  return (
    <div>
      <GetDomClass />
      <GetDomFunc />
    </div>
  );
}

class GetDomClass extends React.Component {
  constructor(props) {
    super(props);
    this.divRef = createRef(null);
  }
  componentDidMount() {
    if (this.divRef.current) {
      console.log(this.divRef.current);
      console.log(document.getElementById("hello_in_class"));
    }
  }

  render() {
    return (
      <div ref={this.divRef}>
        this is the divRef dom in class<div id="hello_in_class">hello</div>
      </div>
    );
  }
}

function GetDomFunc() {
  const inputRef = useRef(null);

  return (
    <div>
      <input ref={inputRef} />
      <button onClick={() => inputRef.current.focus()}>focus</button>
    </div>
  );
}
